﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QMessageBox>
#include <thread>
#include <atomic>
#include <chrono>
#include <QDateTime>
#include <QTimer>
#include <QStringListModel>
#include <time.h>
#include "AdjustFrom.h"
#include "src/Widget/CustomChart.h"
#include "src/Widget/Gau/dashboard1.h"
#include "DebugForm.h"



QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

//inline void sleep_ms(int t){
//    std::this_thread::sleep_for( std::chrono::milliseconds(t) ) ;
//}
std::chrono::seconds operator"" _s( unsigned long long t ) ;

/**
 * @brief The SwingPara struct
 * @details 模拟摆动时候的参数
 */
struct SwingPara{
    int ms_start;
    int ms_wait;
    int ms_end;
    bool isWise = true; //是否顺时针

    std::atomic<bool> exitGau = ATOMIC_FLAG_INIT;   // 线程退出开关
    int sleepCount = 1;  //摆动间隔
    std::atomic<double>  ssc = {1};    // 慢放细节时间(本来是1秒完成的放大为多少秒)
};



class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    static QStringList ScanSerial();
private:
    Ui::MainWindow *ui;
    AdjustFrom *adj;
    DebugForm *motorDebug;


    void initUIs();
    void initMembers();
    void swingGau();
    void CreatDocks();  // 创建Docker容器
    void ModifyPlots();

    CustomChart *standardPlot;  // 标准曲线示意图
    CustomChart *childPlot;     // 子节点曲线示意图

    CustomChart *plot1;
    CustomChart *plot2;

    Dashboard1 *dash;
    QTimer *timer;

    QStringListModel *model; // 可用的串口

    SwingPara PARA;
    std::atomic<bool> s1 = ATOMIC_FLAG_INIT;
    std::atomic<bool> s2 = ATOMIC_FLAG_INIT;
    std::atomic<bool> s3 = ATOMIC_FLAG_INIT;




private slots:
    void processCharData(InputPara );
    void on_actionGau_triggered();
    void on_actionMotor_triggered();
    void on_pb_connect_clicked();




    void refulshPlot();
    void refulshPulse();
    void on_actionScane_triggered();
};
#endif // MAINWINDOW_H
